<<<<<<< HEAD
package com.eminem.hashcode;

public class Test01 {

	public static void main(String[] args) {
		String a = "a";
		System.out.println(a.hashCode());

		System.out.println(new String("a").hashCode());

		System.out.println("97".hashCode());

		String b = "b";
		System.out.println(b.hashCode());

		Student s1 = new Student("zs", "124");
		Student s2 = new Student("zs", "124");
		System.out.println(s1.hashCode());
		System.out.println(s2.hashCode());
		System.out.println("==?:" + (s1 == s2));
		System.out.println("equals?:" + s1.equals(s2));

	}
}

class Student {

	private String name;
	private String card;

	public Student() {
	}

	public Student(String name, String card) {
		this.name = name;
		this.card = card;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((card == null) ? 0 : card.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Student other = (Student) obj;
		if (card == null) {
			if (other.card != null)
				return false;
		} else if (!card.equals(other.card))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

}
=======
package com.eminem.hashcode;

public class Test01 {

	public static void main(String[] args) {
		String a = "a";
		System.out.println(a.hashCode());

		System.out.println(new String("a").hashCode());

		System.out.println("97".hashCode());

		String b = "b";
		System.out.println(b.hashCode());

		Student s1 = new Student("zs", "124");
		Student s2 = new Student("zs", "124");
		System.out.println(s1.hashCode());
		System.out.println(s2.hashCode());
		System.out.println("==?:" + (s1 == s2));
		System.out.println("equals?:" + s1.equals(s2));

	}
}

class Student {

	private String name;
	private String card;

	public Student() {
	}

	public Student(String name, String card) {
		this.name = name;
		this.card = card;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((card == null) ? 0 : card.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Student other = (Student) obj;
		if (card == null) {
			if (other.card != null)
				return false;
		} else if (!card.equals(other.card))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

}
>>>>>>> ce867b29d4fafb4c6031004138aaf83932837c9e
